package com.finance.report.controller;

import com.finance.base.constant.BaseConstants;
import com.finance.base.exception.BaseException;
import com.finance.framework.controller.BaseController;
import com.finance.framework.controller.Result;
import com.finance.report.service.IManSalaryFileService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: gly
 * @Date: Created in 2017-08-10
 */
@Controller
@RequestMapping("/report/uploadfile")
public class ManSalaryFileController extends BaseController {

    @Resource
    private IManSalaryFileService manSalaryFileService;

    @RequestMapping("/index.htm")
    public String index() {
        return "report/uploadfile/index";
    }

    @RequestMapping("/generate")
    public Result generate(String salaryMonth, HttpServletRequest request) {
        if (StringUtils.isEmpty(salaryMonth)) {
            throw new BaseException(BaseConstants.ERR_PARAM_MISS);
        }
        String msg = manSalaryFileService.upload(salaryMonth);
        if(BaseConstants.ERR_UNCOMITTESORDERS_EXISTS.equals(msg)) {
            return getFailResult("0022","所选月份存在未计算完成的订单");
        }
        return getSuccessResult("文件生成成功!");
    }

}
